package cn.edu.xmu.oomall.customer.dao.bo;

import cn.edu.xmu.javaee.core.aop.CopyFrom;
import cn.edu.xmu.javaee.core.model.bo.OOMallObject;
import cn.edu.xmu.javaee.core.model.dto.UserDto;
import cn.edu.xmu.oomall.customer.controller.dto.CustomerDto;
import cn.edu.xmu.oomall.customer.dao.CustomerDao;
import cn.edu.xmu.oomall.customer.mapper.po.CustomerPo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author 谢传艳
 * @date 2024/12/18
 */
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@ToString(callSuper = true, doNotUseGetters = true)
@CopyFrom({CustomerPo.class, CustomerDto.class})
public class Customer extends OOMallObject implements Serializable {

    //账号是否有效

    public static final Byte VALID = 0;

    public static final Byte INVALID = 1;

    //无积分
    public static final Long NO_POINT = 0L;

    //默认创建者
    public static final Long DEFAULT_CREATOR_ID = 1L;
    public static final String DEFAULT_CREATOR_NAME = "admin";

    //默认部门
    public static final Long DEFAULT_DEPART_ID = 1L;
    //默认级别
    public static final Integer DEFAULT_USER_LEVEL = 2;
    //默认过期时间
    public static final int DEFAULT_EXPIRE_TIME = 3600;


    private String userName;
    private String password;
    private String name;
    private Long point;
    private Byte invalid;
    private String mobile;

    @Setter
    @ToString.Exclude
    @JsonIgnore
    private CustomerDao customerDao;

    public void modifiedMyselfInfo(Customer customer, UserDto user) {
        this.setUserName(customer.getUserName());
        this.setMobile(customer.getMobile());
        this.setModifier(user);
        this.setGmtModified(LocalDateTime.now());
        customerDao.save(this);
    }

    public void delete(UserDto user) {
        this.setModifier(user);
        this.setGmtModified(LocalDateTime.now());
        customerDao.delete(this);
    }

    public void ban(UserDto user) {
        this.setInvalid(INVALID);
        this.setModifier(user);
        this.setGmtModified(LocalDateTime.now());
        customerDao.save(this);
    }

    public void release(UserDto user) {
        this.setInvalid(VALID);
        this.setModifier(user);
        this.setGmtModified(LocalDateTime.now());
        customerDao.save(this);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getPoint() {
        return point;
    }

    public void setPoint(Long point) {
        this.point = point;
    }

    public Byte getInvalid() {
        return invalid;
    }

    public void setInvalid(Byte invalid) {
        this.invalid = invalid;
    }

    public Long getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(Long creatorId) {
        this.creatorId = creatorId;
    }

    public String getCreatorName() {
        return creatorName;
    }

    public void setCreatorName(String creatorName) {
        this.creatorName = creatorName;
    }

    public Long getModifierId() {
        return modifierId;
    }

    public void setModifierId(Long modifierId) {
        this.modifierId = modifierId;
    }

    public String getModifierName() {
        return modifierName;
    }

    public void setModifierName(String modifierName) {
        this.modifierName = modifierName;
    }

    public LocalDateTime getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(LocalDateTime gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    public LocalDateTime getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(LocalDateTime gmtModified) {
        this.gmtModified = gmtModified;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }
}
